/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pfc.arbol;

import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import pfc.comun.IDEpfc;
import pfc.comun.Proyecto;
import pfc.gui.CGModelEdit2;
import pfc.modeloer.ERAttrib;
import pfc.modeloer.ERElement;
import pfc.modeloer.ERModel;
import pfc.modeloer.ERRelationShip;
import pfc.modeloer.EREntity;
import pfc.utils.Utils;

/**
 *
 * @author xandru
 */
class ERModelTreeNode extends PFCTreeNode {
    private ERModel _ermodel;
    public ERModelTreeNode (Proyecto p, String n)
    {
        super(p,n);
    }

    @Override
    protected void construirMenuContexto()
    {
       super.construirMenuContexto();
/*
       JMenuItem mi = new JMenuItem("Editar Modelo E-R");
        mi.setActionCommand("showProperties");
        //mi.addActionListener(this);


        mi.addActionListener(new java.awt.event.ActionListener() {
                                public void actionPerformed(java.awt.event.ActionEvent e) {
                                    edicionModeloER();
            }



        });

        popupMenu.add(mi);
        mi.setEnabled(true);
        popupMenu.add(new JSeparator());
 */
 }

    private void edicionModeloER() {
                CGModelEdit2 er = new CGModelEdit2();
                IDEpfc.app.addParaEditar(er,"Modelo ER");
    }

    void buildTree(ERModel modelo) {
        //ERModel modelo = Utils.XMLToERModel(entityModelFile);
        System.out.println(modelo.getName());
        for (EREntity e: modelo.getEntityList())
        {
            if (e.getErElementType()==ERElement.EntityType.RelationShip)
                continue;
            //System.out.println(e.getName());
            EntityTreeNode n = new EntityTreeNode(this.proyecto,e.getName(),e);
            for (ERAttrib a: e.getAttribs())
            {
              //System.out.println(a);
              AttributeTreeNode an = new AttributeTreeNode(this.proyecto,a.getName());
              n.add(an);
            }

            this.add(n);
        }
        /*
        for (ERRelationShip rel: modelo.getRelationShipList())
        {
            RelationTreeNode rn = new RelationTreeNode(this.proyecto, rel.getName());
            this.add(rn);
        }
         * 
         */
    }

    void setERModel(ERModel modelo) {
        this._ermodel = modelo;
    }

    public ERModel getERmodel() {
        return _ermodel;
    }

}
